import axios from 'axios'
import ELEMENT from 'element-ui'
import router from '../router'

// 用于登录的axios请求
const loginInstance = axios.create({
  baseURL: '',
  // headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  withCredentials: false // 是否允许携带cookie进行请求，默认false
})

// axios实例
const instance = axios.create({
  baseURL: '',
  // headers: {'Content-Type': 'application/x-www-form-urlencoded'},
  withCredentials: false
})

// request请求前的处理-在登录之后，获取到token，对instance实例进行配置
instance.interceptors.request.use(
  // 成功
  config => {
    if (access_token) {
      // config.headers.Authorization = `Bearer ${access_token}`
      config.headers.Authorization = access_token;
    }
    return config;
  },
  // 失败
  error => {
    return Promise.reject(error);
  }
);
